﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace YXShop.Web.admin.include
{
    public partial class selproductinfo : System.Web.UI.Page
    {
        protected string str = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                str = ChangeHope.WebPage.PageRequest.GetQueryString("w_s_pro_Designation");
            }
            GetList();
        }
        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        protected void GetList()
        {
            YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            YXShop.BLL.Product.ProductInfo data = new YXShop.BLL.Product.ProductInfo();
            ChangeHope.DataBase.DataByPage dataPage = data.GetList();

            YXShop.BLL.Product.ProductAuction pabll = new YXShop.BLL.Product.ProductAuction();

            YXShop.BLL.Product.Product_IntegratePurchas pipbll = new YXShop.BLL.Product.Product_IntegratePurchas();

            YXShop.BLL.OrderCard.OrderCardInfo ocibll = new YXShop.BLL.OrderCard.OrderCardInfo();
            //第一步先添加表头
            table.AddHeadCol("90%", "商品名称");
            table.AddHeadCol("10%", "库存");
            table.AddRow();
            //添加表的内容
            if (dataPage.DataReader != null)
            {
                while (dataPage.DataReader.Read())
                {
                    bool cod = false;
                    switch (str)
                    {
                        case "3":
                            if (pipbll.GetModelProductID(Convert.ToInt32(dataPage.DataReader["pro_ID"].ToString())) != null)
                            {
                                cod = true;
                            }
                            break;
                        case "5":
                            if (pabll.GetModelProductID(Convert.ToInt32(dataPage.DataReader["pro_ID"].ToString())) != null)
                            {
                                cod = true;
                            }
                            break;
                        case "7":
                            if (ocibll.GetModelProductID(Convert.ToInt32(dataPage.DataReader["pro_ID"].ToString())) != null)
                            {
                                cod = true;
                            }
                            break;
                    }
                    double price = Convert.ToDouble(dataPage.DataReader["pro_ShopPrice"].ToString());
                    string memberPrice = dataPage.DataReader["pro_RatingDiscount"].ToString();
                    string specificationValue = "";
                    int productStock = Convert.ToInt32(dataPage.DataReader["pro_Stock"].ToString());

                    if (!cod)
                    {


                        if (!string.IsNullOrEmpty(dataPage.DataReader["pro_Specifications"].ToString()))
                        {
                            YXShop.BLL.Product.ProductSpecification proSpe = new YXShop.BLL.Product.ProductSpecification();
                            List<YXShop.Model.Product.ProductSpecification> proSpeList = proSpe.GetSpecification(Convert.ToInt32(dataPage.DataReader["pro_ID"].ToString()));
                            if (proSpeList.Count > 0)
                            {
                                for (int i = 1; i < proSpeList.Count; i++)
                                {
                                    string speId=proSpeList[i].Id.ToString();
                                    specificationValue = proSpeList[i].Specifications;
                                    productStock = proSpeList[i].ProductStock;
                                    string specVa = "";
                                    if (specificationValue != "")
                                    {
                                        specVa = "&nbsp;&nbsp;" + specificationValue + "";
                                    }
                                    table.AddCol("<span id='" + dataPage.DataReader["pro_ID"].ToString() + "' style='cursor:hand' ondblclick=\"ReturnValue();\" onClick=\"SelectLable(this);sFiles('" + dataPage.DataReader["pro_ID"].ToString() + "," + speId + "','" + dataPage.DataReader["pro_Name"].ToString() + specVa + "');\">" + dataPage.DataReader["pro_Name"].ToString() + specVa + "</span>");
                                    table.AddCol(string.Format("{0}{1}", productStock, dataPage.DataReader["pro_Unit"].ToString()));
                                    table.AddRow();
                                }
                            }
                        }
                        else
                        {
                            table.AddCol("<span id='" + dataPage.DataReader["pro_ID"].ToString() + "' style='cursor:hand' ondblclick=\"ReturnValue();\" onClick=\"SelectLable(this);sFiles('" + dataPage.DataReader["pro_ID"].ToString() + "','" + dataPage.DataReader["pro_Name"].ToString() + "');\">" + dataPage.DataReader["pro_Name"].ToString() + "</span>");
                            table.AddCol(string.Format("{0}{1}", dataPage.DataReader["pro_Stock"].ToString(), dataPage.DataReader["pro_Unit"].ToString()));
                            table.AddRow();
                        }
                    }
                    
                }
            }
            string view = table.GetTable() + dataPage.PageToolBar;
            dataPage.Dispose();
            dataPage = null;
            this.Literal1.Text = view;
        }
        protected void lbSearch_Click(object sender, EventArgs e)
        {
            GetList();
        }
    }
}
